using System.Collections.Generic;
using System.Linq;
using Game.Command;
using Game.Level;
using Game.Map;
using Game.Plugin;
using Game.Plugin.Parse;

namespace DebugPlugin
{
    public class DebugPlugin : AbstractPlugin
    {
        static readonly DebugPlugin _DebugPlugin;

        public static DebugPlugin Instance
        {
            get { return _DebugPlugin; }
        }

        public static void Register()
        {
        }

        static DebugPlugin()
        {
            _DebugPlugin = new DebugPlugin();
        }

        public DebugPlugin()
            : base(PluginManager.Instance.RootPlugin, "debug")
        {
        }

        public void Init(
            CommandExecutor executor,
            IGameMapView view,
            GameLevels levels) 
        {
            new ShowAllPlugin(executor, view, levels, this);
            new FieldsPlugin(this, view);
            new VehiclesPlugin(this, view);
            new QueryPlugin(this, levels);
        }

        public override ICodeObject Parse(
            string token, 
            ParserContext context)
        {
            IExpression e = new DebugExpression();
            context.Stack.Push(e);
            return e;
        }
    }

    class DebugExpression : IExpression
    {
        public object Interpret(Dictionary<string, ICodeObject> variables)
        {
            return DebugPlugin.Instance.Children.Aggregate(
                "", (current, e) => current + (e.Name + " "));
        }
    }
}

